Improve the reliability of the libusb module.
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 30 Apr 2006 18:58:18 +0000 (18:58 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sun, 30 Apr 2006 18:58:18 +0000 (18:58 +0000)
A) eliminate reset - this avoids a race between us and the host OS stack
   discovering devices.
B) Call full device close when doing device discovery to drain stray
   bulk/intr request packets.

gpsbabel/jeeps/gpslibusb.c

index 879d2b7c307a554258f5496a5be2355d19d9623f..8890092b0c1e3d5fc18e8839b802b2b10d015e8f 100644 (file)
@@ -115,21 +115,11 @@ garmin_usb_start(struct usb_device *dev)
        int i;
 
        if (udev) return;
-       /*
-        * Linux _requires_ the reset.   OSX doesn't work if we 
-        * DO reset it.  I really should study this more, but for 
-        * now, we'll just avoid the reset on Apple's OSX.
-        */
-#if !defined (__APPLE__)
-       udev = usb_open(dev);
-       usb_reset(udev);
-       usb_close(udev);
-#endif /* APPLE */
 
        udev = usb_open(dev);
        atexit((void(*)())gusb_teardown);
 
-       if (!udev) { fatal("usb_open failed\n"); }
+       if (!udev) { fatal("usb_open failed: %s\n", usb_strerror()); }
        /*
         * Hrmph.  No iManufacturer or iProduct headers....
         */
@@ -194,7 +184,13 @@ void garmin_usb_scan(libusb_unit_data *lud, int req_unit_number)
                                        continue;
                                if (req_unit_number < 0) {
                                        garmin_usb_start(dev);  
-                                       gusb_teardown(NULL);
+                                       /* 
+                                        * It's important to call _close
+                                        * here since the bulk/intr models
+                                        * may have a "dangling" packet that
+                                        * needs to be drained.
+                                        */             
+                                       gusb_close(NULL);
                                } else 
                                if (req_unit_number == found_devices)
                                        garmin_usb_start(dev);